
package com.scs.application.modules.upms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;

import com.scs.application.modules.upms.entity.ReportChartField;
import com.scs.application.modules.upms.request.ReportChartFieldQueryRequest;
import com.scs.application.modules.upms.service.ReportChartFieldService;

import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* 图表字段 controller
*/
@AllArgsConstructor
@RestController
@RequestMapping("/upms/report_chart_fields")
public class ReportChartFieldController extends CrudController<ReportChartField,String,ReportChartFieldService> implements ImAndExAbleController<ReportChartFieldQueryRequest> {

    @GetMapping("/page")
    public PageResult page(ReportChartFieldQueryRequest request) {
        IPage page = service.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(ReportChartFieldQueryRequest request) {
        List<ReportChartField> list = service.list(request);
        return CommonResult.ok("查询成功", list);
    }


    @PutMapping("/batch_save")
    public CommonResult batchSave(@RequestBody @Valid ReportChartField[] children) {
        if (children == null || children.length == 0) {
            return CommonResult.error("保存失败");
        }
        boolean bSuccess = service.saveOrUpdateBatch(Lists.newArrayList(children));
        return bSuccess ? CommonResult.ok("保存成功") : CommonResult.error("保存失败");
    }
}
